package org.example.trans.demos.test;

import lombok.extern.slf4j.Slf4j;
import org.example.trans.demos.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Slf4j
@Service
public class LogService {
    @Autowired
    private LogInfoMapper logInfoMapper ;
    @Transactional(propagation = Propagation.NESTED)
    public void insertLog(){
        UserInfo userInfo = new UserInfo() ;
        userInfo.setUserName("t1");
        userInfo.setPassword("t1");
        logInfoMapper.insert(userInfo) ;
       try{

           int a = 10/0 ;
       }catch (Exception e){
           log.info("发生异常") ;
           TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
       }


    }
}
